/*
 * @lc app=leetcode id=232 lang=cpp
 *
 * [232] Implement Queue using Stacks
 */

class MyQueue {

    class stack {
        public:
            bool empty() { return dq.empty();}
            int top() { return dq.back();}
            void push(int x) { return dq.push_back(x);}
            int pop() { int v = dq.back(); dq.pop_back(); return v;}

        private:
            deque<int> dq;
    };

    stack s1, s2;
public:
    /** Initialize your data structure here. */
    MyQueue() { 
    }
    
    /** Push element x to the back of queue. */
    void push(int x) {
        if (!s2.empty()) {
            while(!s2.empty()) {
                int v = s2.pop();
                s1.push(v);
            }
        }
        s1.push(x);
    }
    
    /** Removes the element from in front of queue and returns that element. */
    int pop() {
        int v = 0;
        peek();
        v = s2.pop();
        return v;
    }
    
    /** Get the front element. */
    int peek() {
        int v = 0;
        if (s2.empty()) {
            while(!s1.empty()) { 
                v = s1.pop();
                s2.push(v);
            } 
        } else {
            v = s2.top();
        }
        return v;
    }
    
    /** Returns whether the queue is empty. */
    bool empty() {
        return s1.empty() && s2.empty();
    }
};

/**
 * Your MyQueue object will be instantiated and called as such:
 * MyQueue* obj = new MyQueue();
 * obj->push(x);
 * int param_2 = obj->pop();
 * int param_3 = obj->peek();
 * bool param_4 = obj->empty();
 */

